import os
from pathlib import Path
import requests

def get_default_download_folder():
    import winreg
    sub_key = r'SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders'
    with winreg.OpenKey(winreg.HKEY_CURRENT_USER, sub_key) as key:
        download_dir = winreg.QueryValueEx(key, '{374DE290-123F-4565-9164-39C4925E467B}')[0]
    return download_dir

def download_game(url=None):
    url = 'https://flingtrainer.com/downloads/MoDHtMC4CYSp67LjC34YQQ,,'
    headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36'}

    res = requests.get(url, headers=headers)
    # 获取程序文件名
    file_name = res.headers.get('content-disposition').split('"')[1]
    path_h = os.path.join(get_default_download_folder(), file_name)

    with open(path_h, 'wb') as f:
        f.write(res.content)



if __name__ == '__main__':
    download_game()